<template>
  <div v-if="visible">
    <el-dialog :visible.sync="visible"
               title=""
               :modal="false"
               class="user-dialog add-or-updata"
               width="70%"
               :before-close="closeDialog"
               :close-on-click-modal="false"
               :close-on-press-escape="false">
      <search @sumbit='sumbit'>
        <!--  搜索项 -->
        <template slot='form'>
          <el-form :inline='true'
                   @submit.native.prevent
                   :model='dataForm'
                   ref='dataForm'>
            <el-form-item prop='dataIdentification'>
              <el-input v-model.trim='dataForm.dataIdentification'
                        class='form-item'
                        clearable
                        maxlength="50"
                        show-word-limit
                        placeholder='数据标识'></el-input>
            </el-form-item>
            <el-form-item prop='resultDate'>
              <el-date-picker v-model="dataForm.resultDate"
                              type="date"
                              clearable
                              value-format="yyyy-MM-dd"
                              format="yyyy-MM-dd"
                              placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-form>
        </template>
      </search>
      <table-template :tableData='tableData'
                      :loading='dataListLoading'
                      :fieldManagement='false'
                      :index='true'
                      :dataList='dataList'>
      </table-template>
      <el-pagination :current-page='page'
                     :page-sizes='[10, 20, 50, 100]'
                     :total='total'
                     layout='total, sizes, prev, pager, next'
                     @size-change='pageSizeChangeHandle($event, getData)'
                     @current-change='pageCurrentChangeHandle($event, getData)'>
      </el-pagination>
    </el-dialog>
  </div>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import minFormValidate from '@/mixins/form-validate'
import tableTemplate from '@/components/table-template'
import Search from '@/components/search/search'
export default {
  mixins: [mixinViewModule, minFormValidate],
  data () {
    return {
      mixinViewModuleOptions: {
        deleteImgURL: '',
        getDataListURL: '', // 数据列表接口，API地址
        getDataListIsPage: true, // 数据列表接口，是否需要分页？
        addURL: '', // 添加或修改接口，API地址
        updateURL: '', // 添加或修改接口，API地址
        getDataInfoURL: '', // 数据详情，API地址
        deleteURL: '', // 删除接口，API地址
        deleteIsBatch: true, // 删除接口，是否需要批量？
        exportURL: '' // 导出接口，API地址
      },
      visible: false,
      dataForm: {
        dataIdentification: '',
        resultDate: ''
      },
      page: 1, // 当前页码s
      pageSize: 10, // 每页数
      total: 0 // 总条数
    }
  },
  components: { tableTemplate, Search },
  computed: {
    tableData () {
      return [
        { label: '数据标识', width: '120', prop: 'dataIdentification' },
        { label: '结果', width: '120', prop: 'result' },
        { label: '数据单位', width: '120', prop: 'dataUnit' },
        { label: '创建时间', width: '120', prop: 'createDate' }
      ]
    }
  },
  methods: {
    init (data) {
      this.dataForm.id = data.id
      this.$nextTick(() => {
        this.getData()
      })
      this.visible = true
    },
    sumbit () {
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          this.getData()
        }
      })
    },
    getData () {
      if (this.dataForm.resultDate === 'null' || !this.dataForm.resultDate) {
        this.dataForm.resultDate = ''
      }
      this.$http.get(`/tb/devicePolling/queryResultPage?resultDate=${this.dataForm.resultDate}&dataIdentification=${this.dataForm.dataIdentification}&did=${this.dataForm.id}&pageSize=${this.pageSize}&page=${this.page}`).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.dataList = res.data.data
        this.total = res.data.total
      })
    },

    closeDialog () {
      this.visible = false
      this.dataForm.resultDate = ''
      this.dataForm.id = ''
      this.dataForm.dataIdentification = ''
    }
  }
}
</script>

<style lang="scss" scoped></style>
